package com.nicky.kids;


import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;

import com.nicky.kids.Utility.DateUtil;
import com.nicky.kids.Utility.DisplayUtil;
import com.nicky.kids.Utility.IntentUtil;
import com.nicky.kids.Utility.PhotoUtil;
import com.nicky.kids.Utility.SDCardUtil;
import com.nicky.kids.Utility.TLog;

import java.io.File;

public class ModifyActivity extends Activity {
    private static final String TAG = "nick_ModifyPhotoActivity";
    private ImageView mPhotoPreview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_modify);

        Bitmap bitmap = preparePhoto();

        mPhotoPreview = (ImageView)this.findViewById(R.id.photo_preview);
        mPhotoPreview.setImageBitmap(bitmap);
    }

    private Bitmap preparePhoto() {
        File photo = new File(SDCardUtil.getKidsDir(), this.getIntent().getStringExtra("name"));
        int requiredWidth = DisplayUtil.getDisplayMetrics(this).widthPixels;
        int requiredHeight = -1;
        Bitmap bitmap = PhotoUtil.getFitBitmap(photo.getAbsolutePath(), requiredWidth, requiredHeight);
        TLog.e(TAG, bitmap.getWidth()+" "+bitmap.getHeight());
        return bitmap;
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        //getMenuInflater().inflate(R.menu.home, menu);

        menu.add("next").setIcon(android.R.drawable.ic_menu_save).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

        return true;
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // If the nav drawer is open, hide action items related to the content view
//        boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
//        menu.findItem(R.id.action_websearch).setVisible(!drawerOpen);
        return super.onPrepareOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
//            case android.R.id.home:
//                // 当Action Bar的图标被单击时执行下面的Intent
//                Intent intent = new Intent(this, Android123.class);
//                startActivity(intent);
//                break;
        }

        TLog.e("nick", "menu selected: "+item.getTitle());

        String selectedItem = item.getTitle().toString();
        if (selectedItem.equals("next")) {
            Intent intent = new Intent(ModifyActivity.this, PublishActivity.class);
            IntentUtil.startIntent(ModifyActivity.this, intent);
        }


        return super.onOptionsItemSelected(item);
    }
}
